import { login } from '@/api/user'
import { setToken, getToken, removeToken } from '@/utils/auth'

const state = {
  token: getToken()
}
const mutations = {
  setToken(state, payload) {
    state.token = payload
    setToken(payload)
  },
  // 退出登录
  logout(state) {
    state.token = ''
    removeToken()
  }
}
const actions = {
  // 去登录请求
  async goLogin(context, payload) {
    const res = await login(payload)
    context.commit('setToken', res.token)
  }

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

